{extend name="base/form_base" /}
{block name="style"}
<style type="text/css">

</style>
{/block}
{block name="content"}
<div class="layui-fluid">
<form class="layui-form" id="ajaxform" onsubmit="return false">
    <input type="hidden" name="id" value="{$data.id ?? ''}">
          <div class="layui-form-item">
            <label class="layui-form-label">标题：</label>
            <div class="layui-input-block">
              <input name="title" required="" lay-verify="required" placeholder="请输入标题" autocomplete="off" class="layui-input" type="text" value="{$data.title ?? ''}">
            </div>
          </div>
          <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">内容：</label>
            <div class="layui-input-block">
              <textarea id="demo" style="display: none;" name='content'>{$data.content ?? ''}</textarea>
            </div>
          </div>
          <div class="layui-form-item">
            <div class="layui-input-block">
              <button class="layui-btn site-demo-layedit" data-type="ajax">发布公告</button>
            </div>
          </div>
        </form>
</div>  
{/block}
{block name="script"}
<script>
  layui.use(['form', 'layedit'], function(){
  var layedit = layui.layedit;
  var form = layui.form;
  layedit.set({
      uploadImage: {
        url: '{:C("system_url")}/api/Upload/upload_img2'
        ,type: 'post' //默认post
      }
    });
  var text = layedit.build('demo',{
    height: 500 //设置编辑器高度
  }); //建立编辑器
  //编辑器外部操作
  var active = {
    ajax: function(){
      layedit.sync(text);
      var post_data = $("#ajaxform").serialize();
      $.ajax({
            url:"{:url('admin/notice/editNotice')}",
            type:"POST",
            data:post_data,
            success:function(ret){
                if (ret.code == 0) {
                  layer.msg('操作成功');
                  parent.$(".layui-laypage-btn")[0].click();
                }
                if (ret.code == 1) {
                    layer.msg(ret.msg);
                }
            }
        });
    }
  };
  $('.site-demo-layedit').on('click', function(){
    var type = $(this).data('type');
    active[type] ? active[type].call(this) : '';
  });
});
</script> 
{/block}